<?php
require_once("ma.abs.php");

class pduma1 extends MA {

	var $data;

	function getName()
	{
		return "192.168.1.1_pdu";
	}

	function getTableorSingleData($source,$timeperiods,$report,$obspoints,$type,$view,$filter,$sort,$rowlimit,$arguments)
	{
		$ret=array();
		$count=0;
		foreach($timeperiods as $tp) 
		{
			$ret[$tp['resolution']][$tp['timestamp']][1]=array();
			$pduReading=`rrdtool lastupdate outlet17.rrd | cut -d ' ' -f 1,2 | tail -n+3`;
			while($str=fgets($pduReading)) 
			{
				$time = $this->getTime($str);

				if($rowlimit==0 or $rowlimit>$count++)
					$ret[$tp['resolution']][$tp['timestamp']][1][]=array($time,substr($str,11));
			}
			fclose($interfaceStats);
		}
		return $ret;
	}

	function getDatasources()
	{
		return array('pduma1'=>"pduma1");
	}
	function getObspoints($source)
	{
		return array(array('id'=>1,
			   'name'=>"localhost"));
	}


	function getTimeInfo($source)
	{
		$first=$this->getTime(`head /home/madave/Documents/perfSONARNC/syslogma/testSyslog.db -n 1`);
		$last=$this->getTime(`tail /home/madave/Documents/perfSONARNC/syslogma/testSyslog.db|tail -n 1`);			
			
		$ret=array();
		$ret[]=array('id'=>1,
					'name'=>"5 min",
					'duration'=>300,
					'plot_from'=>"",
					'first'=>$first,
					'last'=>$last);
		$ret[]=array('id'=>2,
					'name'=>"Hour",
					'duration'=>3600,
					'plot_from'=>1,
					'first'=>$first,
					'last'=>$last);
		print "getTimeInfo returns:";
		print_r ($ret);
		return $ret;
	}

	private function getTime($str)
	{
		preg_match("/^\d{10}/", $str, $result);
		return $result[0];
	}
}
?>
